package com.atguigu.spzx.manager.service.impl;

import com.atguigu.spzx.manager.mapper.BrandMapper;
import com.atguigu.spzx.manager.service.BrandService;
import com.atguigu.spzx.model.entity.product.Brand;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service
public class BrandServiceImpl implements BrandService {
    @Resource
    BrandMapper brandMapper;
    @Override
    public PageInfo<Brand> getPage(Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum,pageSize ,true ,true , null);
        List<Brand> brands = brandMapper.selectPage();
        PageInfo<Brand> pageInfo = new PageInfo<>(brands);
        return pageInfo;
    }

    @Override
    public void deleteById(Long id) {
        brandMapper.deleteById(id);
    }

    @Override
    public Brand getById(Long id) {
        return brandMapper.selectById(id);
    }

    @Override
    public void updateById(Brand brand) {
        brand.setUpdateTime(new Date());
        brandMapper.updateById(brand);
    }

    @Override
    public void save(Brand brand) {
        brand.setCreateTime(new Date());
        brand.setUpdateTime(new Date());
        brandMapper.save(brand);
    }

    @Override
    public List<Brand> listAll() {

        return brandMapper.selectAll();
    }
}
